#!coding=utf-8
from django.template.context import RequestContext
from django.shortcuts import render_to_response
from weixin.api.common import getWebAccToken
from weixin.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.http.response import HttpResponse

def memview(request):  
    code=request.GET.get("code");
    openid=request.session.get('openid',False)
    if openid == False:
        openid=getWebAccToken(code)
        request.session['openid']=openid
    try:
        user=User.objects.get(openid=openid);
        params={'balance':user.balance,'score':user.score,'openid':openid}
    except ObjectDoesNotExist:
        User(openid=openid).save()
        params={'balance':'0','score':'0','openid':openid}
    template='membercenter.html'
    return render_to_response(template,params,context_instance=RequestContext(request))


    
    
    
